<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of GestorPasajero
 *
 * @author Karla
 */
include_once("../../util/Cadena.php");
include_once("../../comunicacion/db/MySQL.php");

class GestorPasajero {

    //put your code here
    public function buscarPasajero($nombrePasajero) {

	$cadena = new Cadena();
	$campoSelect;
	$campoWhere;

	$listaPalabrasSimilares = $cadena->separarEnSimilares($nombrePasajero);
	error_log('$listaPalabrasSimilares: ' . var_export($listaPalabrasSimilares, true));
	foreach ($listaPalabrasSimilares as $palabraSimilar) {
	    $campoSelect[] = "if(INSTR(cli.cliente,'" . $palabraSimilar["palabra_similar"] . "')<>0," . $palabraSimilar["ponderacion"]  . ",0)";
	    $campoWhere[] = "cli.cliente like ('%" . $palabraSimilar["palabra_similar"] . "%')";
	}
	$query = "select cli.idcliente,cli.cliente,cli.fechacreacion
," . implode(" + ", $campoSelect) . "as ponderacion
from cliente cli 
where (" . implode(" or ", $campoWhere) . ") 
order by ponderacion desc";

	echo $query;
	$myqsql = new MySQL();
	$conexion = $myqsql->getConexion();
	$result = $conexion->query($query);
	$conexion->close();
	
	return $result;
    }

}

?>
